package com.yzx.lifeassistants.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.bean.SharePlatform;

/**
 * @Description: 分享列表适配器
 * @author: yzx
 * @time: 2016-4-15 下午8:44:37
 */
public class ShareListAdapter extends BaseAdapter {
	private List<SharePlatform> dataList;
	private SharePlatform data;
	private LayoutInflater inflater;
	private ViewHolder holder;

	public ShareListAdapter(Context context, List<SharePlatform> dataList) {
		this.dataList = dataList;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_dialog_share, parent,
					false);
			holder = new ViewHolder();
			holder.iconIV = (ImageView) convertView
					.findViewById(R.id.item_dialog_share_icon_iv);
			holder.nameTV = (TextView) convertView
					.findViewById(R.id.item_dialog_share_name_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		data = dataList.get(position);
		holder.iconIV.setBackgroundResource(data.getIconId());
		holder.nameTV.setText(data.getName());
		return convertView;
	}

	static class ViewHolder {
		ImageView iconIV;// 图标
		TextView nameTV;// 平台名
	}
}
